﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace BlockOS.Client
{
    public static class Settings
    {
        public enum ControlMode: int
        {
            Touchscreen = 0,
            KeyboardAndMouse,
            Gamepad
        }

        public static string PLAYER_NAME;

        public static float SCREEN_OFFSET_LEFT = 0.0f;
        public static float SCREEN_OFFSET_RIGHT = 0.0f;

        public static ControlMode CONTROL_MODE = 0;

        public static void Load()
        {
            PLAYER_NAME = PlayerPrefs.GetString("player_name", "Unnamed");
            SCREEN_OFFSET_LEFT = PlayerPrefs.GetFloat("display_offset_left", 0);
            SCREEN_OFFSET_RIGHT = PlayerPrefs.GetFloat("display_offset_right", 0);
            CONTROL_MODE = (ControlMode)PlayerPrefs.GetInt("control_mode", (int)ControlMode.Touchscreen);
            if ((int)CONTROL_MODE < 0 || (int)CONTROL_MODE > (int)ControlMode.Gamepad)
            {
                CONTROL_MODE = 0;
            }
        }

        public static void Save()
        {
            PlayerPrefs.SetString("player_name", PLAYER_NAME);
            PlayerPrefs.SetFloat("display_offset_left", SCREEN_OFFSET_LEFT);
            PlayerPrefs.SetFloat("display_offset_right", SCREEN_OFFSET_RIGHT);
            PlayerPrefs.SetInt("control_mode", (int)CONTROL_MODE);
            PlayerPrefs.Save();
        }
    }
}
